package com.youran.restful.webprinter.model;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

public class FileInfo {

	private String fileName;
	private String fileType;
	private Date lastUpdate;
	
	private File baseFile;
	private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	
	public FileInfo(File file) {
		this.baseFile = file;
		init();
	}
	
	private void init() {
		try {
			
			String fName = baseFile.getName();
			
			int spiltIndex = fName.lastIndexOf(".");
			this.setFileName(fName.substring(0, spiltIndex));
			this.setFileType(fName.substring(spiltIndex+1));
			this.setLastUpdate(new Date(baseFile.lastModified()));
			
		} catch(Exception e) {
			
		}
	}

	public String getLastUpdateStr() {
		return dateFormat.format(lastUpdate);
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public String getFileType() {
		return fileType;
	}

	public void setFileType(String fileType) {
		this.fileType = fileType;
	}

	public Date getLastUpdate() {
		return lastUpdate;
	}

	public void setLastUpdate(Date lastUpdate) {
		this.lastUpdate = lastUpdate;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("FileInfo [fileName=");
		builder.append(fileName);
		builder.append(", fileType=");
		builder.append(fileType);
		builder.append(", lastUpdate=");
		builder.append(getLastUpdateStr());
		builder.append("]");
		return builder.toString();
	}
	
	
}
